#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<algorithm>
using namespace std;
string s;
int n;
map<char, int>mp;
int main()
{
	int t;
	cin >> t;
	while (t--) {
		cin >> s;
		mp.clear();
		int ma = 0;
		for (int i = 0; i < s.size(); i++) {
			mp[s[i]]++;
			ma = max(ma, mp[s[i]]);
		}
		string temp = "";
		for (int i = 0; i < 26; i++) {
			char k = (char)('a' + i);
			if (mp[k]) {
				temp += k;
			}
		}
		for (int i = 25; i >= 0; i--) {
			char k = (char)('a' + i);
			if (mp[k]) {
				temp += k;
				mp[k]--;
			}
		}
		ma--;
		while (ma--) {
			for (int i = 0; i < 26; i++) {
				char k = (char)('a' + i);
				if (mp[k]) {
					temp = k + temp;
				}
			}
			for (int i = 0; i < 26; i++) {
				char k = (char)('a' + i);
				if (mp[k]) {
					temp += k;
					mp[k]--;
				}
			}
		}
		cout << temp << endl;
	}
	return 0;
}